﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 广告数据类
    /// </summary>
    public class Ad
    {
        public Ad()
        {
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAdcd,FEntityNo,FAdName,FAdProp,FDataType,FOldFileName,FSvrFileName,FAdContent,FAdType,FAdUrl,FIsUse,FAdWidth,FAdHeight ");
            strSql.Append(" FROM t_ad ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (top > 0)
            {
                strSql.Append(" top " + top.ToString());
            }
            strSql.Append(" FAdcd,FEntityNo,FAdName,FAdProp,FDataType,FOldFileName,FSvrFileName,FAdContent,FAdType,FAdUrl,FIsUse,FAdWidth,FAdHeight ");
            strSql.Append(" FROM t_ad ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_DSJCJ.Model.Ad DataRowToModel(DataRow row)
        {
            ElingOA6_DSJCJ.Model.Ad model = new ElingOA6_DSJCJ.Model.Ad();
            if (row != null)
            {
                if (row["FAdcd"] != null)
                {
                    model.FAdcd = row["FAdcd"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FAdName"] != null)
                {
                    model.FAdName = row["FAdName"].ToString();
                }
                if (row["FAdProp"] != null)
                {
                    model.FAdProp = row["FAdProp"].ToString();
                }
                if (row["FDataType"] != null)
                {
                    model.FDataType = row["FDataType"].ToString();
                }
                if (row["FOldFileName"] != null)
                {
                    model.FOldFileName = row["FOldFileName"].ToString();
                }
                if (row["FSvrFileName"] != null)
                {
                    model.FSvrFileName = row["FSvrFileName"].ToString();
                }
                if (row["FAdContent"] != null && row["FAdContent"].ToString() != "")
                {
                    model.FAdContent = (byte[])row["FAdContent"];
                }
                if (row["FAdType"] != null)
                {
                    model.FAdType = row["FAdType"].ToString();
                }
                if (row["FAdUrl"] != null)
                {
                    model.FAdUrl = row["FAdUrl"].ToString();
                }
                if (row["FIsUse"] != null && row["FIsUse"].ToString() != "")
                {
                    model.FIsUse = decimal.Parse(row["FIsUse"].ToString());
                }
                if (row["FAdWidth"] != null && row["FAdWidth"].ToString() != "")
                {
                    model.FAdWidth = int.Parse(row["FAdWidth"].ToString());
                }
                if (row["FAdHeight"] != null && row["FAdHeight"].ToString() != "")
                {
                    model.FAdHeight = int.Parse(row["FAdHeight"].ToString());
                }
            }
            return model;
        }
    }
}
